package com.wujiansima.renyisima.demo;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Demo5 {
    public static void main(String[] args) {
        String name = "D:\\Typora";
        File file = new File(name);
        Map<String,Integer> map = new HashMap<>();
        getCount(map,file);
        Set<Map.Entry<String, Integer>> entries = map.entrySet();
        for (Map.Entry<String, Integer> entry : entries) {
            System.out.println(entry.getKey() + "  " + entry.getValue());
        }
    }

    private static void getCount(Map<String, Integer> map, File file) {
        if (file.isFile()){
            return;
        }
        File[] files = file.listFiles();
        for (File f : files) {
            if (f.isFile()){
                String name = f.getName();
                String[] arr = name.split("\\.");
                String s = arr[arr.length - 1];
                if (map.containsKey(s)){
                    Integer integer = map.get(s);
                    integer++;
                    map.put(s,integer);
                }else{
                    map.put(s,1);
                }

            }else{
                getCount(map,f);
            }
        }
    }
}
